<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-09-20
 * 版    本：1.0.0
 * 功能说明：文章控制器。
 *
 **/

namespace Qwadmin\Controller;

use Vendor\Tree;

class TeacherController extends ComController
{

    public function index(){
        $list=M('teacher')->select();
        $this->assign('list',$list);
        $this->display();
    }


    public function index_add(){
        $id=I('id');
        if($id){
            $info=M('teacher')->where(array('id'=>$id))->find();
            $this->assign('info',$info);
        }
        $this->display();
    }

    public function index_update()
    {
        $id=$_POST['id'];
        $data['name']=$_POST['name'];
        $data['h_img']=$_POST['h_img'];
        $data['check_num']=$_POST['check_num'];
        $data['content']=$_POST['content'];
        $data['l_img']=$_POST['l_img'];
        $data['intro']=$_POST['intro'];
        $data['pop_num']=$_POST['pop_num'];
        $data['u_time']=time();
        if ($id) {
            //编辑
            M('teacher')->data($data)->where(array('id'=>$id))->save();
            $this->success('恭喜！编辑成功！',U('index'));
        } else {
            //新增
            $data['c_time']=time();
            M('teacher')->data($data)->add();
            $this->success('恭喜！新增成功！',U('index'));
        }
    }


    public function index_del(){
        $ids = $_POST['ids'];
        $id=I('id');
        if ($ids) {
            $ids = implode(',', $ids);
            $map['id'] = array('in', $ids);
            M('teacher')->where($map)->delete();
            $this->success('恭喜，删除成功！');
        }else{
            if($id){
                M('teacher')->where(array('id'=>$id))->delete();
                $this->success('恭喜，删除成功！');
            }else{
                $this->error('请选择删除对象');
            }
        }

    }



    public function video(){
        $list=M('video')->join('left join qw_teacher on qw_teacher.id=qw_video.t_id')->field('qw_video.*,qw_teacher.name')->select();
        $this->assign('list',$list);
        $this->display();
    }


    public function video_add(){
        $id=I('id');
        if($id){
            $info=M('video')->where(array('id'=>$id))->find();
            $this->assign('sel_id',$info['t_id']);
            $this->assign('info',$info);
        }
        $teacherlist=M('teacher')->field('id,name')->select();
        $this->assign('teacherlist',$teacherlist);
        $this->display();
    }

    public function video_update()
    {
        $id = $_POST['id'];
        $data['title'] = $_POST['title'];
        $data['intro'] = $_POST['intro'];
        $data['image'] = $_POST['image'];
        $data['t_id'] = $_POST['t_id'];
        $data['join_num'] = $_POST['join_num'];
        $data['price'] = $_POST['price'];
        $data['call_num'] = $_POST['call_num'];
        $data['u_time'] = time();
        if ($id) {
            //编辑
            M('video')->data($data)->where(array('id' => $id))->save();
            $this->success('恭喜！编辑成功！', U('video'));
        } else {
            //新增
            $data['c_time'] = time();
            M('video')->data($data)->add();
            $this->success('恭喜！新增成功！', U('video'));
        }
    }

    public function video_del(){
        $ids = $_POST['ids'];
        $id=I('id');
        if ($ids) {
            $ids = implode(',', $ids);
            $map['id'] = array('in', $ids);
            M('video')->where($map)->delete();
            $this->success('恭喜，删除成功！');
        }else{
            if($id){
                M('video')->where(array('id'=>$id))->delete();
                $this->success('恭喜，删除成功！');
            }else{
                $this->error('请选择删除对象');
            }
        }

    }









}